import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yt_devops/styles/styles.dart';

class YtButton extends StatefulWidget {
  final String? text;

  final Color? color;

  final Color diableColor;

  final Color? textColor;

  final VoidCallback? onPress;

  final double? fontSize;

  final int maxLines;

  final MainAxisAlignment mainAxisAlignment;

  final Size? size;

  final BorderRadius? radius;

  final bool enabled;

  final BorderSide? borderSide;

  const YtButton(
      {super.key,
      this.text,
      this.color = Colour.primaryColor,
      this.textColor = Colors.white,
      this.diableColor = Colour.diabledButtoBgColor,
      this.onPress,
      this.fontSize,
      this.mainAxisAlignment = MainAxisAlignment.center,
      this.size,
      this.radius,
      this.enabled = true,
      this.borderSide,
      this.maxLines = 1});

  @override
  State<YtButton> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<YtButton> {
  @override
  Widget build(BuildContext context) {
    return TextButton(
      style: TextButton.styleFrom(
        disabledBackgroundColor: widget.diableColor,
        minimumSize: widget.size ?? const Size(311, 50),
        backgroundColor: widget.enabled ? widget.color : widget.diableColor,
        padding: const EdgeInsets.all(0),
        shape: RoundedRectangleBorder(
          // side:
          //     widget.borderSide ?? const BorderSide(color: Colors.transparent),
          borderRadius: widget.radius ?? BorderRadius.circular(8),
        ),
      ),
      child: Flex(
        mainAxisAlignment: widget.mainAxisAlignment,
        direction: Axis.horizontal,
        children: <Widget>[
          Expanded(
            child: Text(widget.text!,
                style: TextStyle(
                    color: widget.textColor ?? Theme.of(context).primaryColor,
                    fontSize: widget.fontSize ?? 16.sp,
                    height: 1),
                textAlign: TextAlign.center,
                maxLines: widget.maxLines,
                overflow: TextOverflow.ellipsis),
          )
        ],
      ),
      onPressed: () {
        if (widget.enabled) {
          widget.onPress?.call();
        }
      },
    );
  }
}
